package com.empire.module.member.dal.mysql.warninggatherperson;

import java.util.*;

import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.empire.framework.mybatis.core.mapper.BaseMapperX;
import com.empire.module.member.dal.dataobject.warninggatherperson.WarningGatherPersonDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import com.empire.module.member.controller.admin.warninggatherperson.vo.*;
import org.springframework.util.CollectionUtils;

/**
 * 聚集预警参与人员关联表（1条记录对应1人参与1次聚集） Mapper
 *
 * @author 主席大人
 */
@Mapper
public interface WarningGatherPersonMapper extends BaseMapperX<WarningGatherPersonDO> {

    default PageResult<WarningGatherPersonDO> selectPage(WarningGatherPersonPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WarningGatherPersonDO>()
                .eqIfPresent(WarningGatherPersonDO::getGatherId, reqVO.getGatherId())
                .eqIfPresent(WarningGatherPersonDO::getPersonId, reqVO.getPersonId())
                .orderByDesc(WarningGatherPersonDO::getId));
    }

    // 批量插入
    default void batchInsert(List<WarningGatherPersonDO> list) {
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        insertBatch(list); // 依赖MyBatis-Plus的批量插入方法
    }

    // 根据聚集ID删除关联记录
    @Delete("DELETE FROM member_warning_gather_person WHERE gather_id = #{gatherId}")
    void deleteByGatherId(Long gatherId);

}